package com.cncbox.controller;

import com.cncbox.entity.Article;
import com.cncbox.entity.NoteResult;
import com.cncbox.service.ArticleService;
import com.cncbox.service.ClickLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 前台内容获取
 * Created by songs on 2016/4/8.
 */

@Controller
public class FrontDeskController {

    @Autowired
    private ArticleService articleService;

    @Autowired
    private ClickLinkService clickLinkService;

    //首页、我们、联系我们
    @RequestMapping(value = "/HWT")
    @ResponseBody
    public NoteResult HWT(Article article) throws Exception {
        NoteResult noteResult = new NoteResult();
        if (article != null) {
            noteResult = articleService.selectOrderByClass(article);
        } else {
            noteResult.setStatus(0);
            noteResult.setMsg("PARAMETER_ERROR");
        }
        return noteResult;
    }

    //带分页查询文章
    @RequestMapping(value = "/CI")
    @ResponseBody
    public NoteResult cI(Article article, Integer pageNo, Integer pageSize) throws Exception {
        NoteResult noteResult = new NoteResult();
        if (article != null) {
            noteResult = articleService.selectStatusOrderByClass(article, pageNo, pageSize);
        } else {
            noteResult.setStatus(0);
            noteResult.setMsg("PARAMETER_ERROR");
        }
        return noteResult;
    }

    //查询详细内容
    @RequestMapping(value = "Q")
    @ResponseBody
    public NoteResult qC(Integer conId) throws Exception {
        NoteResult noteResult = new NoteResult();
        if (conId != null && 0 < conId) {
            noteResult = articleService.queryContentById(conId);
        } else {
            noteResult.setStatus(0);
            noteResult.setMsg("PARAMETER_ERROR");
        }
        return noteResult;
    }

    //下导航
    @RequestMapping(value = "/N")
    @ResponseBody
    public NoteResult n(String nName) throws Exception {
        NoteResult result = new NoteResult();
        if (nName != null && !"".equals(nName)) {
            result = clickLinkService.selectClickLink(nName);
        } else {
            result.setStatus(0);
            result.setMsg("PARAMETER_ERROR");
        }
        return result;
    }


}
